package org.btik.light.mobile.ui.devs.camquadruped;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Switch;
import androidx.annotation.Nullable;
import org.btik.context.SimpleContext;
import org.btik.light.mobile.R;
import org.btik.light.mobile.meta.VideoChannelType;
import org.btik.light.mobile.ui.devs.VideoCapability;
import org.btik.light.mobile.ui.factory.DevPanelActivity;
import org.btik.video.server.VideoServer;


import static org.btik.light.mobile.platform.conf.ContextGlobalNames.*;
import static org.btik.light.mobile.ui.devs.camquadruped.CamQuadrupedHandlers.*;

public class CamQuadrupedActivity extends DevPanelActivity implements VideoCapability {

    private Switch videoSwitch;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setContentView(R.layout.cam_quadruped);
        bindAction();
        loadVideo();
    }

    @SuppressLint("ClickableViewAccessibility")
    private void bindAction() {
        bind(R.id.up_, GO_FORWARD);
        bind(R.id.left, TO_TURN_LEFT);
        bind(R.id.right, TO_TURN_RIGHT);
        bind(R.id.down, GO_BACKWARD);
        bind(R.id.stop, TO_STOP);
        bind(R.id.servo_reset, SERVO_RESET);
        bind(R.id.light_switch, LIGHT_SWITCH);
        bind(R.id.step_high_switch, STEP_HIGH_SWITCH);
        bind(R.id.step_length_switch, STEP_LENGTH_SWITCH);

    }

    private void loadVideo() {
        videoSwitch = bind(R.id.video_switch, VIDEO_SWITCH);
        SurfaceView video = findViewById(R.id.video);
        bindChannel(video.getHolder(),defaultDevMo.getVideoChannelType());
        videoSwitch.setVisibility(View.VISIBLE);
        video.setVisibility(View.VISIBLE);
    }

    @Override
    protected void onDestroy() {
        VIDEO_0FF.accept(videoSwitch);
        super.onDestroy();
    }

}
